<?php

/**
 * recuperar actions.
 *
 * @package    atenea
 * @subpackage recuperar
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class recuperarActions extends sfActions
{
  /**
   * Executes index action
   *
   */
  public function executeIndex()
  {
  	$this->getUser()->getAttributeHolder()->clear();
    $this->forward('recuperar', 'formrecup');
  }
  public function executeFormrecup()
  {
    
    if ($this->getRequestParameter('aceptar')){
		
        return $this->redirect('recuperar/verificar');
      }
    else if ($this->getRequestParameter('atras')){
      
        return $this->redirect('login/acceso');
      } 
    else{    	
    	/*$this->redirect('recuperar/clave');*/
    	sfView::SUCCESS;
    }
  }

  public function executeVerificar()
  {  	
  	$user = $this->getUser();  	
  	if (!$user->isAuthenticated())
	{
  		$correo = $this->getRequestParameter('email');  	  	
	  	if($user->Verificando($correo))
	  	{
	  		return $this->redirect('recuperar/envioemail');	
	  	}else return $this->redirect('recuperar/formrecup');
	}else return $this->redirect('login/acceso');	      		
  	
  } 
  
public function executeEnvioemail()
{
	//indicamos el inicio de nuestro codigo php
    //mail('corvramirez@yahoo.com', 'Prueba de correo', 'aqui va tu clave 123456 ');
    $clave = $this->getUser()->getAttribute('clave');  
    $email = $this->getUser()->getAttribute('correo');
    
    ////////////////////////////////////////77
    	include(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
		require_once($sf_symfony_lib_dir.'/addon/sfMail.class.php');
        //require_once '/sf/sfMail.class.php';
		 
		// class initialization
		//$mail = sfMail::newInstance('PhpMailer');
		
		$mail = new sfMail(); 
		$mail->initialize();
		$mail->setMailer('smtp');
		$mail->setDomain('mail.cantv.net.ve');
		 
		// definition of the required parameters
		
		//print ' "'.$email.'"  ';exit;
		$mail->addAddress('coramirez@gmail.com');		
		$mail->setSender('coramirez@intercable.net.ve', 'Symfony');
		$mail->setFrom('coramirez@intercable.net.ve', 'Symfony');
		$mail->addReplyTo('cramirez.cidesa@gmail.com');
		$mail->setCharset('utf-8');
		$mail->setSubject('Recuperacion de Clave');
		$mail->setBody('Gracias por usar recuperacion de clave del sistema Atenea, su clave actual es3: "'.$clave.'"  ');
		 
		// send the email
		$mail->send(); 
    
    
    ////////////////////////////////////////////777
    
    
    
    
    
    
    return $this->redirect('recuperar/mensaje');
}
  
public function executeMensaje()
  {
  	$this->setFlash('notice', 'Su clave ha sido enviada al su correo');   	 
   	$this->redirect('recuperar/formrecup');   		
	return sfView::SUCCESS;
  }
}
